/**
 * 购买单次票
 */
package com.kerrykidz.membership.controller;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.kerrykidz.common.Constants;
import com.kerrykidz.common.ORDER_CONSTANTS;
import com.kerrykidz.common.service.ICommonService;
import com.kerrykidz.dao.model.GblPosDiscountEntity;
import com.kerrykidz.filemanagement.service.ISalesService;
import com.kerrykidz.filemanagement.service.IVipService;
import com.kerrykidz.membership.dao.model.CusGuaEntity;
import com.kerrykidz.membership.dao.model.CusMemEntity;
import com.kerrykidz.membership.dao.model.GblCusCReltypeEntity;
import com.kerrykidz.membership.service.IGuaService;
import com.kerrykidz.membership.service.IMemberService;
import com.kerrykidz.membership.service.ISingleService;
import com.kerrykidz.sales.dao.model.PosOrderEntity;
import com.kerrykidz.sales.dao.model.PosOrderPrdEntity;
import com.kerrykidz.sales.service.IOrderService;
import com.kerrykidz.sales.service.IPaymentService;
import com.kerrykidz.scminvoicing.dao.model.GblScmPrdEntity;
import com.kerrykidz.scminvoicing.service.IScmInvocingProductInfoService;
import com.kerrykidz.system.dao.model.GblCusCCountryEntity;
import com.kerrykidz.system.dao.model.SecUsrEntity;
import com.kerrykidz.system.dao.model.SysParaEntity;
import com.kerrykidz.system.service.IGblService;
import com.kerrykidz.system.util.DateUtil;
import com.kerrykidz.system.util.UserUtil;
import com.kerrykidz.system.vo.UserInfo;
import com.rdp.framework.exception.RDPException;
import com.rdp.util.GenerationUUID;

/**
 * @author Tik
 * 
 */
@RequestMapping("membership/single")
@Controller
public class SingleController {

	@Autowired
	private ICommonService commonService;
	@Autowired
	private ISingleService singleService;
	@Autowired
	private IMemberService memberService;
	@Autowired
	private IGuaService guaService;
	@Autowired
	private IScmInvocingProductInfoService productService;
	@Autowired
	private IOrderService orderService;
	@Autowired
	private IPaymentService paymentService;
	@Autowired
	private IVipService vipService;
	@Autowired
	private ISalesService salesService;
	@Autowired
	private IGblService gblService;

	/**
	 * 跳转到购买单次票界面
	 * 
	 * @param cpnId
	 *                玩伴券编号
	 * @param cpnAmount
	 *                玩伴券优惠额度
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/jumpSingleTicket")
	public ModelAndView jumpSingleTicket(
					@RequestParam(value = "cpnId", required = false) String cpnId,
					@RequestParam(value = "cpnAmount", required = false) String cpnAmount,
					@RequestParam(value = "fkBdymemId", required = false) String fkBdymemId)
					throws RDPException {
		ModelAndView mv = new ModelAndView("membership/membership_single");
		if (StringUtils.isNotBlank(cpnId)) {
			mv.addObject("cpnId", cpnId);
			mv.addObject("cpnAmount", cpnAmount);
		}
		if (StringUtils.isNotBlank(fkBdymemId)) {
			mv.addObject("fkBdymemId", fkBdymemId);
		}
		return mv;
	}

	/**
	 * 跳转到访客界面
	 * 
	 * @return
	 * @throws RDPException 
	 */
	@RequestMapping("/jumpVisitor")
	public ModelAndView jumpVisitor() throws RDPException {

		ModelAndView mv = new ModelAndView("membership/membership_visitor_detail");
		
		List<GblCusCReltypeEntity> reltypeList = memberService.findReltypes();
		mv.addObject("reltypeList", reltypeList);

		// 销售列表
		List<SecUsrEntity> salesList = salesService.listSales();
		mv.addObject("salesList", salesList);

		// 国籍列表
		List<GblCusCCountryEntity> countryList = gblService.selectAll();
		mv.addObject("countryList", countryList);
		return mv;
	}


	/**
	 * 保存会员
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/saveMember")
	@ResponseBody
	public Map<String, String> saveMember(CusMemEntity member) throws RDPException {
		Map<String, String> map = new HashMap<String, String>();
		UserInfo user = UserUtil.getUserFromSession();
		member.setFkBranId(user.getBranId());
		member.setModiBy(user.getUserId());
		if (StringUtils.isBlank(member.getPkMemId())) {
			if (memberService.checkFingerprintExist(member.getFing1()) != 0 || memberService.checkFingerprintExist(member.getFing2()) != 0) {
				map.put("result", Constants.FAILURE);
				map.put("message", "指纹已存在于其它用户，不可重复创建！");
				return map;
			}
			member.setStatus(Constants.MEMBER_STATUS_CREATE);
			if (StringUtils.isBlank(member.getFamilyId())) {
				String familyId = GenerationUUID.getGenerationUUID();
				member.setFamilyId(familyId);
				map.put("familyId", familyId);
			}
			vipService.createVip(member);
			map.put("memberId", member.getPkMemId());
		} else {
			vipService.updateVip(member);
			map.put("memberId", member.getPkMemId());
		}
		map.put("result", Constants.SUCCESS);
		return map;
	}

	/**
	 * 验证采集的指纹是否已存在于其它用户
	 * 
	 * @param fingerprint
	 *                指纹数据
	 * @return SUCCESS：不存在 FAILURE：已存在
	 * @throws RDPException
	 * @throws UnsupportedEncodingException
	 * @date: 2014年8月22日
	 */
	@RequestMapping("/checkFingerprintExist")
	@ResponseBody
	public String checkFingerprintExist(String fingerprint) throws RDPException, UnsupportedEncodingException {

		if (fingerprint == null) return Constants.SUCCESS;
		if (memberService.checkFingerprintExist(fingerprint) != 0) {
			return Constants.FAILURE;
		}
		return Constants.SUCCESS;
	}

	/**
	 * 保存监护人
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/saveGua")
	@ResponseBody
	public Map<String, String> saveGua(CusGuaEntity gua) throws RDPException {
		Map<String, String> map = new HashMap<String, String>();
		UserInfo user = UserUtil.getUserFromSession();
		gua.setFkBranId(user.getBranId());
		gua.setModiBy(user.getUserId());
		if (StringUtils.isBlank(gua.getPkGuaId())) {
			if (memberService.checkFingerprintExist(gua.getFing1()) != 0 || memberService.checkFingerprintExist(gua.getFing2()) != 0) {
				map.put("result", Constants.FAILURE);
				map.put("message", "指纹已存在于其它用户，不可重复创建！");
				return map;
			}
			vipService.createGuardian(gua);
		} else {
			vipService.updateGuardian(gua);
		}
		map.put("result", Constants.SUCCESS);
		return map;
	}

	/**
	 * 删除会员
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/deleteMember")
	@ResponseBody
	public String deleteMember(String memberId) throws RDPException {
		CusMemEntity member = new CusMemEntity();
		member.setPkMemId(memberId);
		UserInfo user = UserUtil.getUserFromSession();
		member.setModiBy(user.getUserId());
		memberService.deleteMember(member);
		return Constants.SUCCESS;
	}

	/**
	 * 删除监护人
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/deleteGua")
	@ResponseBody
	public String deleteGua(String guaId) throws RDPException {
		CusGuaEntity gua = new CusGuaEntity();
		gua.setPkGuaId(guaId);
		UserInfo user = UserUtil.getUserFromSession();
		gua.setModiBy(user.getUserId());
		guaService.deleteGua(gua);
		return Constants.SUCCESS;
	}

	/**
	 * 根据姓名或电话号码查询会员
	 * 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/queryMember")
	@ResponseBody
	public List<CusMemEntity> queryMember(
					@RequestParam(value = "nameOrTel") String nameOrTel,
					@RequestParam(value = "cpnId", required = false) String cpnId,
					@RequestParam(value = "fkBdymemId", required = false) String fkBdymemId)
					throws RDPException,
					UnsupportedEncodingException {
		nameOrTel = URLDecoder.decode(nameOrTel, "UTF-8");
		List<CusMemEntity> list = memberService.findMemberByNameOrTel(nameOrTel);
		// 有玩伴券不能在会员身上使用
		if (StringUtils.isNotBlank(cpnId) && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				CusMemEntity mem = list.get(i);
				if ("1".equals(mem.getMemType())) {
					list.remove(i);
					i--;
				}
			}
		}
		return list;

	}

	/**
	 * 根据指纹查询会员
	 * 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/queryMemberByFingerprint")
	@ResponseBody
	public CusMemEntity queryMemberByFingerprint(
					@RequestParam(value = "fingerprint") String fingerprint,
					@RequestParam(value = "cpnId", required = false) String cpnId,
					@RequestParam(value = "fkBdymemId", required = false) String fkBdymemId)
					throws RDPException {
		Object obj = memberService.findFingerprint(fingerprint);
		if (obj instanceof CusMemEntity) {
			CusMemEntity mem = (CusMemEntity) obj;
			// 有玩伴券不能在会员身上使用
			if (StringUtils.isNotBlank(cpnId) && "1".equals(mem.getMemType())) {
				return null;
			}
			return mem;
		}
		return null;

	}

	/**
	 * 根据会员编号查询会员
	 * 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/queryMemberById")
	@ResponseBody
	public CusMemEntity queryMemberById(@RequestParam(value = "memberId") String memberId) throws RDPException {
		CusMemEntity member = memberService.findMemberById(memberId);
		return member;

	}

	/**
	 * 根据监护人编号查询监护人
	 * 
	 * @return
	 * @throws RDPException
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/queryGuaById")
	@ResponseBody
	public CusGuaEntity queryGuaById(@RequestParam(value = "guaId") String guaId) throws RDPException {
		CusGuaEntity gua = guaService.findGuaById(guaId);
		return gua;

	}

	/**
	 * 查询会员及其关联信息
	 * 
	 * @param memberId
	 *                会员编号
	 * @param cpnId
	 *                玩伴券编号
	 * @param cpnAmount
	 *                玩伴券优惠额度
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/queryMemberDetail")
	public ModelAndView queryMemberDetail(
					HttpSession session,
					@RequestParam(value = "memberId", required = false) String memberId,
					@RequestParam(value = "cpnId", required = false) String cpnId,
					@RequestParam(value = "cpnAmount", required = false) String cpnAmount,
					@RequestParam(value = "fkBdymemId", required = false) String fkBdymemId, 
					@RequestParam(value="type",required=false)String type)
					throws RDPException {

		ModelAndView mv = new ModelAndView("membership/membership_single_detail");

		if (StringUtils.isNotBlank(cpnId)) {
			mv.addObject("cpnId", cpnId);
			mv.addObject("cpnAmount", cpnAmount);
		}
		if (StringUtils.isNotBlank(fkBdymemId)) {
			mv.addObject("fkBdymemId", fkBdymemId);
		}
		Date sysdate = new Date();
		if (DateUtil.getDayOfWeek(sysdate) != 1 && DateUtil.getDayOfWeek(sysdate) != 7 && !commonService.isHoliday()) {
			mv.addObject("holiday", "n");
		} else {
			mv.addObject("holiday", "y");
		}
		if (StringUtils.isNotBlank(memberId)) {
			// 会员、非会员信息 兄弟姐妹
			List<CusMemEntity> memList = memberService.findMemberAndSiblingsById(memberId);
			mv.addObject("memList", memList);
			if (memList.size() > 0) {
				mv.addObject("familyId", memList.get(0).getFamilyId());
			}
			mv.addObject("memberId", memberId);
			mv.addObject("type", type);

			// 监护人列表
			List<CusGuaEntity> guaList = memberService.findGuaByMemberId(memberId);
			mv.addObject("guaList", guaList);

			// 玩伴票列表
			if (StringUtils.isBlank(cpnId)) {

				List<List<Map<String, Object>>> vcLists = new ArrayList<List<Map<String, Object>>>();
				for (CusMemEntity member : memList) {
					if (Constants.FAILURE.equals(checkBdycpnCanUse(member.getPkMemId()))) {
						continue;
					}
					List<Map<String, Object>> vcList = memberService.findVoucherCouponsByMemberId(member.getPkMemId());
					if (vcList.size() > 0) {
						vcLists.add(vcList);
					}
				}
				mv.addObject("vcLists", vcLists);
			}
		}

		List<GblCusCReltypeEntity> reltypeList = memberService.findReltypes();
		mv.addObject("reltypeList", reltypeList);

		// 单次票商品列表
		UserInfo user = UserUtil.getUserFromSession();
		GblScmPrdEntity prd = new GblScmPrdEntity();
		prd.setResverseType(Constants.PRODUCT_TYPE_SINGLE);
		prd.setFkBranId(user.getBranId());
		List<GblScmPrdEntity> productList = productService.getProductInfo(prd);
		if (productList.size() > 0) {
			for (GblScmPrdEntity product : productList) {
				GblScmPrdEntity single = productService.findSingleTicket(product.getPkPrdId());
				if (single != null) {
					product.setChdCnt(single.getChdCnt());
					product.setGuaCnt(single.getGuaCnt());
				}
			}
		}
		mv.addObject("productList", productList);

		// 销售列表
		List<SecUsrEntity> salesList = salesService.listSales();
		mv.addObject("salesList", salesList);

		// 国籍列表
		List<GblCusCCountryEntity> countryList = gblService.selectAll();
		mv.addObject("countryList", countryList);

		return mv;

	}

	/**
	 * 验证指定会员是否还有未使用的单次票
	 * @param memberId
	 * @throws RDPException
	 * @date: 2014年11月13日
	 */
	@RequestMapping("/checkEnableSingleByMemberId")
	@ResponseBody
	public String checkEnableSingleByMemberId(String memberId) throws RDPException {

		if (memberService.checkEnableSingleByMemberId(memberId)) {
			return Constants.SUCCESS;
		}
		return Constants.FAILURE;
	}
	
	/**
	 * 验证是否可以使用玩伴券
	 * 
	 * @param fkBdymemId
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月11日
	 */
	public String checkBdycpnCanUse(String fkBdymemId) throws RDPException {
		
		if (Constants.FAILURE.equals(checkCanBuy(fkBdymemId))) {
			return Constants.FAILURE;
		}
		
		// 周末、节假日外来客只有在会员带领下才可以购买，并且会员一天最多只能带2人
		Date sysdate = new Date();
		if (DateUtil.getDayOfWeek(sysdate) != 1 && DateUtil.getDayOfWeek(sysdate) != 7 && !commonService.isHoliday()) {
			return Constants.SUCCESS;
		}
		if (StringUtils.isBlank(fkBdymemId)) {
			return Constants.FAILURE;
		}
		
		if (memberService.checkBdyCount(fkBdymemId) > 2) {
			return Constants.FAILURE;
		}
		return Constants.SUCCESS;
	}
	
	
	/**
	 * 验证是否可以购买商品
	 * 
	 * @param fkBdymemId
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月11日
	 */
	public String checkCanBuy(@RequestParam(value = "memberId") String memberId) throws RDPException {
		
		CusMemEntity member = memberService.findMemberById(memberId);
		if (member == null) {
			return Constants.FAILURE;
		}
		// 过期和黑名单用户不允许购买
		if ("1".equals(member.getIsBlack())) {
			return Constants.FAILURE;
		}
		return Constants.SUCCESS;
	}

	/**
	 * 下单界面
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/findPayment")
	public ModelAndView findPayment(HttpSession session,
					@RequestParam(value = "fkBdycpnId", required = false) String fkBdycpnId,
					@RequestParam(value = "selMemberId") String memberId,
					@RequestParam(value = "pkPrdId") String[] pkPrdIds,
					@RequestParam(value = "quantity") Integer[] quantitys,
					@RequestParam(value = "cpnId", required = false) String cpnId,
					@RequestParam(value = "cpnAmount", required = false) String cpnAmount,
					@RequestParam(value = "fkBdymemId", required = false) String fkBdymemId,
					@RequestParam(value = "recharge", required = false) String recharge,
					@RequestParam(value="type",required=false)String type)
					throws RDPException {
		
		UserInfo user = UserUtil.getUserFromSession();
		GblScmPrdEntity prdEntity = new GblScmPrdEntity();
		prdEntity.setResverseType(Constants.PRODUCT_TYPE_SINGLE);
		prdEntity.setFkBranId(user.getBranId());
		List<GblScmPrdEntity> productList = productService.getProductInfo(prdEntity);
		// 取得购买商品列表
		Map<String, GblScmPrdEntity> prdMap = new HashMap<String, GblScmPrdEntity>();
		for (GblScmPrdEntity prd : productList) {
			prdMap.put(prd.getPkPrdId(), prd);
		}
		boolean canUseCpn = false;
		for (int i = 0; i < quantitys.length; i++) {
			Integer qty = quantitys[i];
			if (qty == null || qty == 0) {
				productList.remove(prdMap.get(pkPrdIds[i]));
			} else {
				prdMap.get(pkPrdIds[i]).setQuantity(qty);
				GblScmPrdEntity single = productService.findSingleTicket(pkPrdIds[i]);
				if (single != null && single.getChdCnt() == 1 && !canUseCpn) {
					// 单次票1+1 才能使用
					prdMap.get(pkPrdIds[i]).setFkBdycpnId(cpnId);
					prdMap.get(pkPrdIds[i]).setFkBdymemId(fkBdymemId);
					canUseCpn = true;
				}
			}
		}
		
		ModelAndView mv = new ModelAndView("membership/membership_single_payment");
		
		if (StringUtils.isNotBlank(recharge) && !"0".equals(recharge)) {
			GblScmPrdEntity rechargePrd = new GblScmPrdEntity();
			rechargePrd.setPrdName("充值");
			rechargePrd.setQuantity(Integer.parseInt(recharge));
			rechargePrd.setProductPrice(1);
			rechargePrd.setFkMemId(memberId);
			productList.add(rechargePrd);
			mv.addObject("rechargeFlag", "1");
		}

		mv.addObject("memberId", memberId);
		mv.addObject("type", type);

		mv.addObject("orderList", productList);
		if (canUseCpn) {
			mv.addObject("cpnAmount", cpnAmount);
		} else {
			mv.addObject("cpnAmount", "0");
		}

		List<GblPosDiscountEntity> discountList = productService.findAllDiscount();
		mv.addObject("discountList", discountList);

		return mv;
	}

	/**
	 * 经理密码验证
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/validationManagerPassword")
	@ResponseBody
	public String validationManagerPassword(@RequestParam(value = "password") String password) throws RDPException {
		
		SecUsrEntity user = commonService.findDiscountUser(password,UserUtil.getUserFromSession().getBranId());
		if (user != null) {
			return user.getPkUsrId();
		}
		return Constants.FAILURE;
	}

	/**
	 * 上传宴请单
	 * 
	 * @param file
	 * @return
	 * @date: 2014年8月14日
	 */
	@RequestMapping(value = "/uploadFete")
	@ResponseBody
	public String uploadFete(MultipartFile file) {
		UserInfo userInfo = UserUtil.getUserFromSession();
		if (null == userInfo) {
			return null;
		}
		SysParaEntity para = commonService.findSysParaById(Constants.SYS_BASE_PATH_FETE);
		String fileName = file.getOriginalFilename();
		int index = fileName.lastIndexOf(".");
		String newFileName = System.currentTimeMillis() + (index > -1 ? fileName.substring(index) : "");
		File targetFile = new File(para.getParaValue(), newFileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}

		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}

		return newFileName;
	}

	/**
	 * 下单
	 * 
	 * @param session
	 * @param memberId
	 *                会员编号
	 * @param pkPrdIds
	 *                商品编号
	 * @param pkDisId
	 *                折扣编号
	 * @param quantitys
	 *                数量
	 * @param productPrice
	 *                商品单价
	 * @param total
	 *                商品金额
	 * @param discountTotal
	 *                折后金额
	 * @param fkBdycpnId
	 *                玩伴券编号
	 * @param fete
	 *                是否宴请
	 * @param fkFeteFile
	 *                商务宴请附件编号
	 * @param amount
	 *                商品总额
	 * @return
	 * @throws Exception
	 * @date: 2014年8月13日
	 */
	@RequestMapping("/placeOrder")
	@ResponseBody
	public String placeOrder(HttpSession session,
					@RequestParam(value = "memberId") String memberId,
					@RequestParam(value = "pkPrdId") String[] pkPrdIds,
					@RequestParam(value = "pkDisId") String[] pkDisIds,
					@RequestParam(value = "fkUsrId") String[] fkUsrIds,
					@RequestParam(value = "quantity") Integer[] quantitys,
					@RequestParam(value = "price") Double[] prices,
					@RequestParam(value = "discountTotal") Double[] discountTotals,
					@RequestParam(value = "fkBdycpnId", required = false) String[] fkBdycpnId,
					@RequestParam(value = "fkBdymemId", required = false) String[] fkBdymemId,
					@RequestParam(value = "fete", required = false) String fete,
					@RequestParam(value = "fkFeteFile", required = false) String fkFeteFile,
					@RequestParam(value = "amount") Double amount,
					@RequestParam(value = "disAmount") Double disAmount)
					throws Exception {

		CusMemEntity member = memberService.findMemberById(memberId);

		PosOrderEntity order = new PosOrderEntity();
		// 订单类型
		order.setOrderType(ORDER_CONSTANTS.ORDER_TYPE_TICKET);
		if (disAmount == 0d) {
			// 订单状态
			order.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_HAS_BEEN_PAY);
		} else {
			// 订单状态
			order.setOrderStatus(ORDER_CONSTANTS.ORDER_STATUS_NOT_PAY);
		}
		// 客户姓名
		if (member != null) {
			order.setCusName(member.getMemName());
		}
		// 商务宴请标记
		order.setFeteFlag(fete == null ? ORDER_CONSTANTS.ORDER_FETE_FLAG_NO : ORDER_CONSTANTS.ORDER_FETE_FLAG_YES);
		// 商务宴请附件编号，关联SYS_ATT_FILE表
		order.setFkFeteFile(fete == null ? "" : fkFeteFile);
		// 总金额
		order.setAmount(amount);
		UserInfo user = UserUtil.getUserFromSession();
		// 下单人，关联SEC_USR表
		order.setFkOperator(user.getUserId());
		// 分店编号，关联GBL_SEC_BRAN表
		order.setFkBranId(user.getBranId());
		order.setModiBy(UserUtil.getUserFromSession().getUserId());

		List<PosOrderPrdEntity> productList = new ArrayList<PosOrderPrdEntity>();
		for (int i = 0; i < pkPrdIds.length; i++) {
			PosOrderPrdEntity product = new PosOrderPrdEntity();
			// 消费类型
			if  (StringUtils.isBlank(pkPrdIds[i])) {
				product.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_CHARGE);
			} else {
				product.setType(ORDER_CONSTANTS.ORDER_PRD_TYPE_PRODUCT);
			}
			// 商品编号
			product.setFkPrdId(pkPrdIds[i]);
			// 会籍或单次票订单关联的会员非会员编号
			product.setFkMemId(memberId);
			// 排序索引
			product.setOrdIndex(i);
			// 购买数量
			product.setCount(quantitys[i]);
			// 商品特殊折扣编号
			product.setFkDisId(pkDisIds.length == 0 ? null : pkDisIds[i]);
			// 商品特殊折扣授权编号
			product.setFkDisusrId(fkUsrIds.length == 0 ? null : fkUsrIds[i]);
			// 单价
			product.setPrice(prices[i]);
			// 折后单价
			product.setDisPrice(discountTotals[i]);
			if (fkBdycpnId.length > 0) {
				GblScmPrdEntity single = productService.findSingleTicket(pkPrdIds[i]);
				if (single != null && single.getChdCnt() == 1) {
					// 订单使用的玩伴券编号
					product.setFkBdycpnId(fkBdycpnId[i]);
					// 使用玩伴券标记
					product.setCouponFlag(ORDER_CONSTANTS.COUPON_FLAG_ABLE);
					// 订单使用的玩伴券非会员编号
					product.setFkBdymemId(fkBdymemId[i]);
				}
			}
			// 是否使用会员续会优惠券标记 =1 是
			product.setExtcpnFlag("0");
			
			productList.add(product);
		}
		String orderId = orderService.createTicket(order, productList, null, UserUtil.getUserFromSession().getAbbrCode());
		return orderId;
	}

	/**
	 * 刷新付款结果
	 * 
	 * @return
	 * @throws RDPException
	 */
	@RequestMapping("/refreshPayResult")
	@ResponseBody
	public String refreshPayResult(String orderId) throws RDPException {
		boolean ispay = paymentService.isPay(orderId);
		return ispay ? Constants.SUCCESS : Constants.FAILURE;
	}

}
